﻿using System;
using System.Collections.Generic;

namespace Gonte.Caching
{
    public static class ObjectCache
    {
        #region Static Methods

        /// <summary>
        /// Retrieves a cache for a specific type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Cache GetCache(Type type)
        {
            lock (lock_)
            {
                if (!caches_.ContainsKey(type))
                {
                    Cache cache = new Cache(configuration_.GetExpirationPolicy());
                    caches_.Add(type, cache);
                }

                return caches_[type];
            }
        } 

        #endregion

        #region Static Fields

        private static Dictionary<Type, Cache> caches_ = new Dictionary<Type, Cache>();
        private static Object lock_ = new Object();
        private static ObjectCacheConfiguration configuration_ = new ObjectCacheConfiguration(); 

        #endregion
    }
}
